package edu.pku.act.test;

import org.json.JSONException;
import org.json.JSONObject;

public class EnvInfo {
	public String domain;
	public String task;
	public String ontology;
	public String attribute;
	public String content;
	public EnvInfo(String domain,String task,String ontology, String attribute, String content) {		
		this.domain = domain;
		this.task = task;
		this.ontology = ontology;
		this.attribute = attribute;
		this.content = content;
	}
	public String toString(){
		JSONObject json = new JSONObject();
		try {
			json.put("domain", domain);
			json.put("task", task);
			json.put("ontology", ontology);
			json.put("attribute", attribute);
			json.put("content", content);
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		
		return json.toString();
	}
	static public EnvInfo fromString(String jsonstr){
		try {
			JSONObject json = new JSONObject(jsonstr);
			return  new EnvInfo(
					json.getString("domain"),
					json.getString("task"),
					json.getString("ontology"),
					json.getString("attribute"),
					json.getString("content"));
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
	}
}
